import pandas as pd
from sklearn.metrics import roc_auc_score
def Cleaning_data():
    # 读取并清理数据
    data = pd.read_csv('../data/train.csv')
    data = data.drop(['EmployeeNumber', 'Over18', 'StandardHours'], axis=1)
    # 存储 AUC
    dict1 = {}

    # 1. 年龄（连续）
    dict1['Age'] = roc_auc_score(data['Attrition'], data['Age'])

    # 2. 出差（分类）
    bus_map = data.groupby('BusinessTravel')['Attrition'].mean()
    dict1['BusinessTravel'] = roc_auc_score(data['Attrition'], data['BusinessTravel'].map(bus_map))

    # 3. 部门
    dep_map = data.groupby('Department')['Attrition'].mean()
    dict1['Department'] = roc_auc_score(data['Attrition'], data['Department'].map(dep_map))

    # 4. 举家距离
    dict1['DistanceFromHome'] = roc_auc_score(data['Attrition'], data['DistanceFromHome'])

    # 5. 文凭
    edu_map = data.groupby('Education')['Attrition'].mean()
    dict1['Education'] = roc_auc_score(data['Attrition'], data['Education'].map(edu_map))

    # 6. 专业
    eduf_map = data.groupby('EducationField')['Attrition'].mean()
    dict1['EducationField'] = roc_auc_score(data['Attrition'], data['EducationField'].map(eduf_map))

    # 8. 环境满意度
    env_map = data.groupby('EnvironmentSatisfaction')['Attrition'].mean()
    dict1['EnvironmentSatisfaction'] = roc_auc_score(data['Attrition'], data['EnvironmentSatisfaction'].map(env_map))

    # 9. 工作投入度
    job_map = data.groupby('JobInvolvement')['Attrition'].mean()
    dict1['JobInvolvement'] = roc_auc_score(data['Attrition'], data['JobInvolvement'].map(job_map))

    # 10. 职位等级
    jobl_map = data.groupby('JobLevel')['Attrition'].mean()
    dict1['JobLevel'] = roc_auc_score(data['Attrition'], data['JobLevel'].map(jobl_map))

    # 11. 职位角色
    jobr_map = data.groupby('JobRole')['Attrition'].mean()
    dict1['JobRole'] = roc_auc_score(data['Attrition'], data['JobRole'].map(jobr_map))

    # 12. 工作满意度
    jobs_map = data.groupby('JobSatisfaction')['Attrition'].mean()
    dict1['JobSatisfaction'] = roc_auc_score(data['Attrition'], data['JobSatisfaction'].map(jobs_map))

    # 13. 婚姻状态
    mar_map = data.groupby('MaritalStatus')['Attrition'].mean()
    dict1['MaritalStatus'] = roc_auc_score(data['Attrition'], data['MaritalStatus'].map(mar_map))

    # 14. 月收入
    dict1['MonthlyIncome'] = roc_auc_score(data['Attrition'], data['MonthlyIncome'])

    # 15. 曾任职公司数量
    num_map = data.groupby('NumCompaniesWorked')['Attrition'].mean()
    dict1['NumCompaniesWorked'] = roc_auc_score(data['Attrition'], data['NumCompaniesWorked'].map(num_map))

    # 17. 是否加班
    overt_map = data.groupby('OverTime')['Attrition'].mean()
    dict1['OverTime'] = roc_auc_score(data['Attrition'], data['OverTime'].map(overt_map))

    # 18. 涨薪百分比
    dict1['PercentSalaryHike'] = roc_auc_score(data['Attrition'], data['PercentSalaryHike'])

    # 19. 绩效（注意：PerformanceRating 在原始数据中几乎全是 3 或 4，可能区分度低）
    pre_map = data.groupby('PerformanceRating')['Attrition'].mean()
    dict1['PerformanceRating'] = roc_auc_score(data['Attrition'], data['PerformanceRating'].map(pre_map))

    # 20. 关系满意度
    rel_map = data.groupby('RelationshipSatisfaction')['Attrition'].mean()
    dict1['RelationshipSatisfaction'] = roc_auc_score(data['Attrition'], data['RelationshipSatisfaction'].map(rel_map))

    # 22. 股票期权等级
    sto_map = data.groupby('StockOptionLevel')['Attrition'].mean()
    dict1['StockOptionLevel'] = roc_auc_score(data['Attrition'], data['StockOptionLevel'].map(sto_map))

    # 23. 总工作年限
    dict1['TotalWorkingYears'] = roc_auc_score(data['Attrition'], data['TotalWorkingYears'])

    # 24. 去年训练次数
    dict1['TrainingTimesLastYear'] = roc_auc_score(data['Attrition'], data['TrainingTimesLastYear'])
    # 移除 AUC ≈ 0.5 的特征（无预测力）
    filtered_dict = {k: v for k, v in dict1.items() if not (0.48 <= v <= 0.52)}
    return filtered_dict

